package com.czl.elm.dao.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.czl.elm.domain.Food;
import com.czl.elm.domain.FoodMenu;
import com.czl.elm.domain.Search;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zuoleiChen
 * @since 2021-05-23
 */
@Mapper
@Repository
public class FoodMapperImpl  {
    @Autowired
    private MongoTemplate mongoTemplate;

    public void addFood(Food food) {

        mongoTemplate.save(food);
    }


    public void addMenu(FoodMenu foodMenu) {
        mongoTemplate.save(foodMenu);
    }

    public Map<String, Integer> selectSpecifications(String foodid) {
        Query query=new Query(Criteria.where("foodid").is(foodid));
        Map<String,Integer> mgt =  mongoTemplate.findOne(query , Map.class,"foodPreferential");
        if(mgt==null)return new HashMap<>();
        return mgt;
    }

    public void t_addShopSpecifications(Map<String, Object> map) {
        mongoTemplate.save(map,"foodPreferential");
    }

    public List<Map> getFoodByFoodIdList(List<String> foodIdList) {
        Query query=new Query(Criteria.where("_id").in(foodIdList));
        query.fields().include("foodUrl").include("foodName").include("foodMoney");
        List<Map> mgt =  mongoTemplate.find(query , Map.class,"food");
        if(mgt==null)return new ArrayList<>();

        return mgt;
    }
}
